<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上架商品</title>
    <script src="../plugins/JQuery/jquery-2.1.1.min.js"></script>
    <script src="../plugins/Bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="../plugins/Bootstrap/css/bootstrap.css">
    <!--线上css-->
    <!--<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">-->
    <script>
        $(function () {
            $('#file').on("change", function () {
                var formData = new FormData();
                for (var i = 0; i < $("#file")[0].files.length; i++) {  //循环获取上传个文件
                    formData.append("file", $("#file")[0].files[i]);
                }
                $.ajax({
                    "url": "/taobei_web/pro/upload", // 上传地址
                    "data": formData,
                    "dataType": "json",
                    "type": "post",
                    "contentType": false, //上传文件一定要是false
                    "processData": false,
                    "success": function (obj) {
                        debugger;
                        if (obj.status == 200) {
                            let text = "";
                            for (let i = 0; i < obj.data.length; i++) {
                                text += "<div><img src=" + obj.data[i] + "></div>"
                            }
                            $("#img").html(text)
                        }
                    }
                });
            })
            let flag;
            $("#but").click(function () {
                if($("#img").text()==null||$("#img").text().length==0){
                    $.ajax({
                        url:'/taobei_web/pro/addProduct',
                        type:'post',
                        data:{
                            name:$("#name").val(),
                            price:$("#price").val(),
                            discountPrice:$("#discount_price").val(),
                            proCost:$("#procost").val(),
                            repertory:$("#repertory").val(),
                            tId:$("#t_id").val(),
                            context:$("#context").val(),
                        },
                        dataType:'json',
                        success(res){
                            alert(res.msg);
                            flag=true;
                                location.href="showStore.html";
                        }
                    })
                }
                else{
                    alert("请选择图片");
                    flag=false
                }
            })
        })

    </script>
    <style>

        #img div{
            float: left;
            margin: 20px;
            width:100px ;
        }
        #img div img{
            width: 100%;
        }
    </style>
</head>
<body>
<div class="item">
    <div id="time"></div>




    <div class="container">
        <div class="row">
            <div class="span12">
                <form class="form-horizontal">
                    <div class="control-group">
                        <div id="img" style="height: 60px">
                        </div>
                      <!--  <div class="controls">
                            <img id="storeImgOld" width="200px" height="200px"><br>
                        </div>-->
                    </div><br><br><br>
                    <div class="control-group">
                        <label class="control-label">照片</label>
                        <div class="controls">
                           <!-- <input type="file" id="storeImg"><br>-->
                            <input type="file" name="files" id="file" multiple="multiple" accept="image/png,image/jpg,image/gif,image/JPEG">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">商品名称</label>
                        <div class="controls">
                            <input type="text" placeholder="商品名称" id="name" class="form-control" style="width: 200px"><br>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">商品价格</label>
                        <div class="controls">
                            <input type="text" placeholder="商品价格" id="price" class="form-control" style="width: 200px"><br>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">优惠价格</label>
                        <div class="controls">
                            <input type="text" placeholder="优惠价格" id="discount_price" class="form-control" style="width: 200px"><br>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">成本价</label>
                        <div class="controls">
                            <input type="text" placeholder="成本价" id="procost" class="form-control" style="width: 200px"><br>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">商品数量</label>
                        <div class="controls">
                            <input type="text" placeholder="商品数量" id="repertory" class="form-control" style="width: 200px"><br>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label">商品类型</label>
                        <div class="controls">
                            <select id="t_id" class="form-control" style="width: 100px">
                                <option value="0">请选择</option>
                                <option value="1">数码电子</option>
                                <option value="2">手机</option>
                                <option value="3">xcx</option>
                                <option value="4">食品</option>
                                <option value="5">饮料</option>
                                <option value="6">零食</option>
                                <option value="7">男装</option>
                                <option value="8">女装</option>
                                <option value="9">电器</option>
                                <option value="10">服装</option>
                                <option value="11">香水彩妆</option>
                                <option value="12">精品男包</option>
                                <option value="13">面部护肤</option>
                                <option value="14">男鞋</option>
                                <option value="15">运动户外</option>
                                <option value="16">品牌服饰</option>
                                <option value="17">服装</option>
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">商品介绍</label>
                        <div class="controls">
                            <textarea class="form-control" rows="3" placeholder="商品介绍" id="context"></textarea>
                        </div>
                    </div>

                    <div class="control-group">
                        <div class="controls">
                            <label class="checkbox"></label>
                           <!-- <input type="button" id="but" value="上传">-->
                            <input type="button" value="添加" id="but" class="btn btn-default">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>